#include "mcl/log.h"

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

#include "mcl/config.h"

#if IS_ON(CONFIG_LOG_DEBUG)
#define LOG_LEVEL_MIN_BUILD LOG_DEBUG
#else
#define LOG_LEVEL_MIN_BUILD LOG_INFO
#endif

enum loglevel LOG_LEVEL_MIN = LOG_LEVEL_MIN_BUILD;

static char const *levelname[] = {
	[LOG_DEBUG] = "debug",
	[LOG_INFO] = "info",
	[LOG_ERROR] = "error",
	[LOG_FATAL] = "fatal",
};

void logging_ap(enum loglevel level, char const *fmt, va_list ap)
{
	fprintf(stderr, "[makec %s]\t", levelname[level]);
	vfprintf(stderr, fmt, ap);
	fprintf(stderr, "\n");
	fflush(stderr);
}

void panic(void)
{
	abort();
	exit(1);
}
